<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <template v-if="isEdit">
        <span @click="searchHistories.splice(0)">全部删除</span>&nbsp;&nbsp;
        <span @click="isEdit = false">完成</span>
      </template>
      <van-icon name="delete" @click="isEdit = true" v-else />
    </van-cell>
    <van-cell
      :title="item"
      v-for="(item, index) in searchHistories"
      :key="index"
      @click="clickHandler(item, index)"
    >
      <van-icon name="close" v-if="isEdit" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: "SearchHistory",
  components: {},
  props: {
    searchHistories: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      isEdit: false,
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    clickHandler(val, idx) {
      if (this.isEdit) {
        //删除操作
        this.searchHistories.splice(idx, 1);
      } else {
        //点击搜索该历史记录的结果--使用子父通信
        this.$emit("search", val);
      }
    },
  },
};
</script>

<style scoped lang="less"></style>
